package jech913;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SungJukV1 extends JFrame {

	private JPanel contentPane;
	private JTextField nameTxt;
	private JTextField korTxt;
	private JTextField engTxt;
	private JTextField mathTxt;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SungJukV1 frame = new SungJukV1();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SungJukV1() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel sungJuk = new JLabel(":: 성적처리 프로그램 ::");
		
		JLabel name = new JLabel("이    름");
		
		nameTxt = new JTextField();
		nameTxt.setColumns(10);
		
		JLabel kor = new JLabel("국    어");
		
		korTxt = new JTextField();
		korTxt.setColumns(10);
		
		JLabel eng = new JLabel("영    어");
		
		engTxt = new JTextField();
		engTxt.setColumns(10);
		
		JLabel math = new JLabel("수    학");
		
		mathTxt = new JTextField();
		mathTxt.setColumns(10);
		
		JButton saveBtn = new JButton("입 력 완 료");
		saveBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//비지니스 로직 처리 (총점, 평균, 학점 계산)
				int tot= Integer.parseInt(korTxt.getText()) +Integer.parseInt(engTxt.getText())+Integer.parseInt(mathTxt.getText());
				float avg= tot/3;
				char grd = '가';
				
				
				switch((int)avg/10){
				case 10:
				case 9:
					grd = '수';
					break;
				case 8:
					grd = '우';
					break;
				case 7:
					grd = '미';
					break;
				case 6:
					grd = '양';
					
				
				}
				
				
				
				
				//프리젠테이션 로직 처리 
				StringBuilder result = new StringBuilder(); 
				result.append("이름:").append(nameTxt.getText()).append("\n");
				result.append("국어:").append(korTxt.getText()).append("\n");
				result.append("영어:").append(engTxt.getText()).append("\n");
				result.append("수학:").append(mathTxt.getText()).append("\n");
				result.append("총점:").append(tot).append("\n");
				result.append("평균:").append(String.format("%3.2f",avg)).append("\n");
				result.append("학점:").append(grd);
		
				JOptionPane.showMessageDialog(null, result);
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(143, Short.MAX_VALUE)
					.addComponent(sungJuk)
					.addGap(174))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(92)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(math, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
							.addGap(61)
							.addComponent(mathTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
							.addGroup(gl_contentPane.createSequentialGroup()
								.addComponent(name)
								.addGap(68)
								.addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGroup(gl_contentPane.createSequentialGroup()
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
									.addComponent(kor, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
									.addComponent(eng, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE))
								.addGap(54)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
									.addComponent(korTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addComponent(engTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))
					.addGap(107))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(163)
					.addComponent(saveBtn)
					.addContainerGap(181, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(sungJuk)
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(name)
						.addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(28)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(korTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(kor))
					.addGap(27)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(engTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(eng))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(36)
							.addComponent(math))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(32)
							.addComponent(mathTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
					.addComponent(saveBtn)
					.addGap(4))
		);
		contentPane.setLayout(gl_contentPane);
	}
}
